<template>
    <el-form :model="form" :rules="rules" ref="form">
      <el-form-item prop="username">
        <el-input v-model="form.username" placeholder="请输入用户名/手机号"></el-input>
      </el-form-item>
      <el-form-item prop="password">
        <el-input v-model="form.password" type="password" placeholder="请输入密码"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm" style="width: 100%">登录</el-button>
      </el-form-item>
      <div class="footer">
        还没有账号？<el-button type="text" @click="toRegister">立即注册</el-button>
      </div>
    </el-form>
</template>

<script>
export default {
  props: {
    visible: Boolean
  },
  data() {
    return {
      form: {
        username: '',
        password: ''
      },
      rules: {
        username: [
          { required: true, message: '请输入用户名', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    submitForm() {
      this.$refs.form.validate(valid => {
        if (valid) {
          // 这里添加登录逻辑
          this.$emit('update:visible', false)
          this.$message.success('登录成功')
        }
      })
    },
    toRegister() {
      this.$emit('update:visible', false)
      this.$emit('register')
    }
  }
}
</script>

<style scoped>
.footer {
  text-align: center;
  color: #666;
}
</style>